package com.authenticateCenter.domain.entity;

import com.authenticateCenter.domain.Checker;
import com.authenticateCenter.domain.entity.util.EntityUtil;
import com.authenticateCenter.service.IAuthorityModuleService;
import com.authenticateCenter.util.MybatisUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.Assert;

/**
 * @author 大忽悠
 * @since 2022年10月19日
 */
@Getter
@Setter
@TableName("authority_module")
public class AuthorityModule implements Serializable, Checker<AuthorityModule> {

    private static final long serialVersionUID = 1L;
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String name;

    private String description;

    private Integer enabled;

    private Integer parentId;


    /**
     * 1.对name进行重复性检查
     * 2.对enabled进行检查
     * 3.对parentId进行检查
     * @param iService
     */
    @Override
    public void insertCheck(IService<AuthorityModule> iService) {
        MybatisUtil.repeatCheck(iService,"name",name,"资源模块名["+name+"]重复");
        EntityUtil.enabledCheck(this);
        //非顶级资源模块,需要校验父资源模块是否存在
        if(parentId!=-1){
            MybatisUtil.resourceMustExist(iService,"id",parentId,"parentId="+parentId+"对应的父资源模块不存在!");
        }
    }
}
